package September29;

import java.io.RandomAccessFile;
import java.io.IOException;

public class RandomAccessFileExample {
    public static void main(String[] args) {
        try {
            RandomAccessFile file = new RandomAccessFile("example.txt", "rw");
            file.seek(0); // 移动到文件开头
            file.writeBytes("Hello World!\n"); // 写入内容

            file.seek(0); // 再次移动到文件开头
            System.out.println(file.readLine()); // 读取内容

            file.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
